<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="房源标题" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入房源标题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="省" prop="province">
        <el-input
          v-model="queryParams.province"
          placeholder="请输入省"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="城市" prop="city">
        <el-input
          v-model="queryParams.city"
          placeholder="请输入城市"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="区" prop="district">
        <el-input
          v-model="queryParams.district"
          placeholder="请输入区"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="房源状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择房源状态" clearable>
          <el-option
            v-for="dict in dict.type.fo_foreclosed_house_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="法拍平台" prop="origin">
        <el-select v-model="queryParams.origin" placeholder="请选择法拍平台" clearable>
          <el-option
            v-for="dict in dict.type.fo_auction_platform"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

<!--      <el-form-item label="区" prop="district">-->
<!--        <el-input-->
<!--          v-model="queryParams.district"-->
<!--          placeholder="请输入区"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="地址" prop="address">-->
<!--        <el-input-->
<!--          v-model="queryParams.address"-->
<!--          placeholder="请输入地址"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->

<!--      <el-form-item label="开始时间" prop="startTime">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.startTime"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择开始时间">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['yipaiju:foreclosed_house:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['yipaiju:foreclosed_house:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['yipaiju:foreclosed_house:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['yipaiju:foreclosed_house:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="foreclosed_houseList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="id" align="center" prop="id" />-->
<!--      <el-table-column label="纬度" align="center" prop="latitude" />-->
<!--      <el-table-column label="经度" align="center" prop="longitude" />-->
<!--      <el-table-column label="position" align="center" prop="position" />-->

      <el-table-column label="省" align="center" prop="province" />
      <el-table-column label="城市" align="center" prop="city" />
<!--      <el-table-column label="区" align="center" prop="district" />-->
<!--      <el-table-column label="地址" align="center" prop="address" />-->
      <el-table-column label="建筑面积" align="center" prop="builtUpAreaSquareCentimeter" >
        <template slot-scope="scope">
          {{scope.row.builtUpAreaSquareCentimeter>0?scope.row.builtUpAreaSquareCentimeter:'--'}}
        </template>
      </el-table-column>
<!--      <el-table-column label="拍卖url" align="center" prop="auctionUrl" />-->
      <el-table-column label="总价" align="center" prop="priceYuan" />
      <el-table-column label="交易价" align="center" prop="dealPrice" />
      <el-table-column label="拍卖阶段" align="center" prop="stage" />
      <el-table-column label="拍卖状态" align="center" prop="status" />
<!--      <el-table-column label="开始时间" align="center" prop="startTime" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="结束时间" align="center" prop="endTime" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="浏览记数" align="center" prop="browseCount" />-->
<!--      <el-table-column label="订阅者计数" align="center" prop="subscriberCount" />-->
<!--      <el-table-column label="参与者计数" align="center" prop="participantCount" />-->
      <el-table-column label="评估价" align="center" prop="estimatePriceYuan" />
      <el-table-column label="市场价" align="center" prop="marketPriceYuan" />
      <el-table-column label="单价" align="center" prop="unitPriceYuan" >
        <template slot-scope="scope">
          {{scope.row.unitPriceYuan>0?scope.row.unitPriceYuan:'--'}}
        </template>
      </el-table-column>
<!--      <el-table-column label="保证金" align="center" prop="depositYuan" />-->
<!--      <el-table-column label="加价幅度" align="center" prop="increasePriceYuan" />-->
      <el-table-column label="法拍平台" align="center" prop="origin" />
<!--      <el-table-column label="住宅_季度名称" align="center" prop="residentialQuarterName" />-->
<!--      <el-table-column label="房屋水平" align="center" prop="houseLevel" />-->
<!--      <el-table-column label="用途" align="center" prop="use" />-->
<!--      <el-table-column label="空闲状态" align="center" prop="freeUpStatus" />-->
<!--      <el-table-column label="详细信息" align="center" prop="viewingDetail" />-->
<!--      <el-table-column label="税" align="center" prop="taxation" />-->
<!--      <el-table-column label="起源" align="center" prop="origin" />-->
<!--      <el-table-column label="法院" align="center" prop="court" />-->
<!--      <el-table-column label="手机号" align="center" prop="phone" />-->
<!--      <el-table-column label="公告" align="center" prop="announcement" />-->
<!--      <el-table-column label="通知" align="center" prop="notice" />-->
<!--      <el-table-column label="描述" align="center" prop="description" />-->
<!--      <el-table-column label="交通" align="center" prop="traffic" />-->
<!--      <el-table-column label="教育" align="center" prop="education" />-->
<!--      <el-table-column label="医院" align="center" prop="hospital" />-->
<!--      <el-table-column label="便利设施" align="center" prop="amenity" />-->
<!--      <el-table-column label="折扣" align="center" prop="discountRate" />-->
<!--      <el-table-column label="房屋类型" align="center" prop="houseType" />-->
<!--      <el-table-column label="上传时间" align="center" prop="uploadTime" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.uploadTime, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="name_md5" align="center" prop="nameMd5" />-->
<!--      <el-table-column label="banner" align="center" prop="banner" />-->
      <el-table-column label="房源标题" align="center" prop="title" :show-overflow-tooltip='true' width="220px">
        <template slot-scope="scope">
          <a :href="scope.row.auctionUrl" target="_blank" style="color: #409EFF">{{scope.row.title}}</a>
        </template>
      </el-table-column>
      <el-table-column label="更新时间" align="center" prop="updateTime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['yipaiju:foreclosed_house:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['yipaiju:foreclosed_house:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改优选房源对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="房源标题" prop="title">
          <el-input v-model="form.title" placeholder="请输入房源标题" disabled/>
        </el-form-item>

        <el-form-item label="交易价" prop="dealPrice">
          <el-input v-model="form.dealPrice" placeholder="请输入交易价" />
        </el-form-item>

<!--        <el-row>-->
<!--          <el-col :span="12">-->
<!--            <el-form-item label="纬度" prop="latitude">-->
<!--              <el-input v-model="form.latitude" placeholder="请输入纬度" />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--          <el-col :span="12">-->
<!--            <el-form-item label="经度" prop="longitude">-->
<!--              <el-input v-model="form.longitude" placeholder="请输入经度" />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--        </el-row>-->
        <el-row>
          <el-col :span="12">
            <el-form-item label="省" prop="province">
              <el-input v-model="form.province" placeholder="请输入省" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="城市" prop="city">
              <el-input v-model="form.city" placeholder="请输入城市" disabled/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="建筑面积" prop="builtUpAreaSquareCentimeter">
              <el-input v-model="form.builtUpAreaSquareCentimeter" placeholder="请输入建筑面积" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="总价" prop="priceYuan">
              <el-input v-model="form.priceYuan" placeholder="请输入总价" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="拍卖状态" prop="status">
              <el-input v-model="form.status" placeholder="请输入拍卖状态" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="拍卖阶段" prop="stage">
              <el-input v-model="form.stage" placeholder="请输入拍卖阶段" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="评估价" prop="estimatePriceYuan">
              <el-input v-model="form.estimatePriceYuan" placeholder="请输入评估价" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="市场价" prop="marketPriceYuan">
              <el-input v-model="form.marketPriceYuan" placeholder="请输入市场价" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="单价" prop="unitPriceYuan">
              <el-input v-model="form.unitPriceYuan" placeholder="请输入单价" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="保证金" prop="depositYuan">
              <el-input v-model="form.depositYuan" placeholder="请输入保证金" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="加价幅度" prop="increasePriceYuan">
              <el-input v-model="form.increasePriceYuan" placeholder="请输入加价幅度" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="浏览记数" prop="browseCount">
              <el-input v-model="form.browseCount" placeholder="请输入浏览记数" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="订阅者计数" prop="subscriberCount">
              <el-input v-model="form.subscriberCount" placeholder="请输入订阅者计数" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="参与者计数" prop="participantCount">
              <el-input v-model="form.participantCount" placeholder="请输入参与者计数" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="开始时间" prop="startTime">
              <el-date-picker clearable
                              v-model="form.startTime"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择开始时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="结束时间" prop="endTime">
              <el-date-picker clearable
                              v-model="form.endTime"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择结束时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="来源" prop="origin">
              <el-input v-model="form.origin" placeholder="请输入起源" disabled/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="法院" prop="court">
              <el-input v-model="form.court" placeholder="请输入法院" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="折扣" prop="discountRate">
              <el-input v-model="form.discountRate" placeholder="请输入折扣" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="上传时间" prop="createTime">
              <el-date-picker clearable
                              v-model="form.createTime"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择上传时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>


        <!--        <el-form-item label="区" prop="district">-->
<!--          <el-input v-model="form.district" placeholder="请输入区" />-->
<!--        </el-form-item>-->
        <el-form-item label="地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入地址" />
        </el-form-item>

        <el-form-item label="拍卖url" prop="auctionUrl">
          <el-input v-model="form.auctionUrl" type="textarea" placeholder="请输入内容" disabled/>
        </el-form-item>
        <el-form-item label="公告" prop="announcement">
          <el-input v-model="form.announcement" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="通知" prop="notice">
          <el-input v-model="form.notice" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="描述" prop="description">
          <el-input v-model="form.description" type="textarea" placeholder="请输入内容" />
        </el-form-item>




<!--        <el-form-item label="住宅_季度名称" prop="residentialQuarterName">-->
<!--          <el-input v-model="form.residentialQuarterName" placeholder="请输入住宅_季度名称" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="房屋水平" prop="houseLevel">-->
<!--          <el-input v-model="form.houseLevel" placeholder="请输入房屋水平" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="用途" prop="use">-->
<!--          <el-input v-model="form.use" placeholder="请输入用途" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="详细信息" prop="viewingDetail">-->
<!--          <el-input v-model="form.viewingDetail" placeholder="请输入详细信息" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="税" prop="taxation">-->
<!--          <el-input v-model="form.taxation" placeholder="请输入税" />-->
<!--        </el-form-item>-->

<!--        <el-form-item label="手机号" prop="phone">-->
<!--          <el-input v-model="form.phone" placeholder="请输入手机号" />-->
<!--        </el-form-item>-->

<!--        <el-form-item label="交通" prop="traffic">-->
<!--          <el-input v-model="form.traffic" type="textarea" placeholder="请输入内容" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="教育" prop="education">-->
<!--          <el-input v-model="form.education" type="textarea" placeholder="请输入内容" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="医院" prop="hospital">-->
<!--          <el-input v-model="form.hospital" type="textarea" placeholder="请输入内容" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="便利设施" prop="amenity">-->
<!--          <el-input v-model="form.amenity" type="textarea" placeholder="请输入内容" />-->
<!--        </el-form-item>-->

<!--        <el-form-item label="name_md5" prop="nameMd5">-->
<!--          <el-input v-model="form.nameMd5" placeholder="请输入name_md5" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="banner" prop="banner">-->
<!--          <el-input v-model="form.banner" type="textarea" placeholder="请输入内容" />-->
<!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listForeclosed_house, getForeclosed_house, delForeclosed_house, addForeclosed_house, updateForeclosed_house } from "@/api/yipaiju/foreclosed_house";

export default {
  name: "Foreclosed_house",
  dicts: ['fo_foreclosed_house_status', 'fo_auction_platform'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 优选房源表格数据
      foreclosed_houseList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        latitude: null,
        longitude: null,
        position: null,
        title: null,
        province: null,
        city: null,
        district: null,
        address: null,
        builtUpAreaSquareCentimeter: null,
        auctionUrl: null,
        priceYuan: null,
        dealPrice: null,
        stage: null,
        status: null,
        startTime: null,
        endTime: null,
        browseCount: null,
        subscriberCount: null,
        participantCount: null,
        estimatePriceYuan: null,
        marketPriceYuan: null,
        unitPriceYuan: null,
        depositYuan: null,
        increasePriceYuan: null,
        residentialQuarterName: null,
        houseLevel: null,
        use: null,
        freeUpStatus: null,
        viewingDetail: null,
        taxation: null,
        origin: null,
        court: null,
        phone: null,
        announcement: null,
        notice: null,
        description: null,
        traffic: null,
        education: null,
        hospital: null,
        amenity: null,
        discountRate: null,
        houseType: null,
        uploadTime: null,
        nameMd5: null,
        banner: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询优选房源列表 */
    getList() {
      this.loading = true;
      listForeclosed_house(this.queryParams).then(response => {
        this.foreclosed_houseList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        latitude: null,
        longitude: null,
        position: null,
        title: null,
        province: null,
        city: null,
        district: null,
        address: null,
        builtUpAreaSquareCentimeter: null,
        auctionUrl: null,
        priceYuan: null,
        dealPrice: null,
        stage: null,
        status: "0",
        startTime: null,
        endTime: null,
        createTime: null,
        browseCount: null,
        subscriberCount: null,
        participantCount: null,
        estimatePriceYuan: null,
        marketPriceYuan: null,
        unitPriceYuan: null,
        depositYuan: null,
        increasePriceYuan: null,
        residentialQuarterName: null,
        houseLevel: null,
        use: null,
        freeUpStatus: "0",
        viewingDetail: null,
        taxation: null,
        origin: null,
        court: null,
        phone: null,
        announcement: null,
        notice: null,
        description: null,
        traffic: null,
        updateTime: null,
        education: null,
        hospital: null,
        amenity: null,
        discountRate: null,
        houseType: null,
        uploadTime: null,
        nameMd5: null,
        banner: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加优选房源";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getForeclosed_house(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改优选房源";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateForeclosed_house(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addForeclosed_house(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除优选房源编号为"' + ids + '"的数据项？').then(function() {
        return delForeclosed_house(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('yipaiju/foreclosed_house/export', {
        ...this.queryParams
      }, `优选房源_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style lang="scss">
  /*.el-tooltip__popper{max-width:80%}*/
</style>
